import { ImageAsset, SpriteFrame, assetManager } from "cc"
import BaseSingleClass from "../base/BaseSingleClass"

export default class SpriteFrameHelper extends BaseSingleClass {
    static getSpriteFrame(url:string):Promise<SpriteFrame> {
        return new Promise<SpriteFrame>((resolve, reject)=>{
            console.log('加载图片：'+url)
            assetManager.loadRemote(url, (err, asset) => {
                if (err) {
                    //console.error(err);
                    reject(err);
                    return;
                }
                const imageAsset = asset as ImageAsset;
                if (imageAsset) {
                    const spriteFrame = SpriteFrame.createWithImage(imageAsset);
                    //spriteFrame.texture=imageAsset
                    resolve(spriteFrame);
                }else{
                    reject(new Error('imageAsset is null'));
                }
            });
        })
        
    }
}